//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Documents
//  File name:	Smart.Documents.Templates.EventReceiver.cs
//  Developer:	Solomatov Igor
//  Created:	03.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using System.Runtime.InteropServices;
using Microsoft.SharePoint;
using Smart.Common;
using Smart.Common.Router;

namespace Smart.Documents.Features
{
	/// <summary>
	/// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
	/// </summary>
	/// <remarks>
	/// The GUID attached to this class may be used during packaging and should not be modified.
	/// </remarks>
	[Guid("dbc6c91a-b323-4611-b7fc-43cff949a9aa")]
	public class SPDocumentsTemplatesEventReceiver : SPFeatureReceiver
	{
		public override void FeatureActivated(SPFeatureReceiverProperties properties)
		{
			H.LT("FeatureActivated: Templates");

			try
			{
				var web = (SPWeb)properties.Feature.Parent;

				using (SPH.SetContext(web.Site, web))
				{
					SetupRouter();
				}
			}
			catch (Exception ex)
			{
				H.LX("SPDocumentsTemplatesEventReceiver.FeatureActivated", ex);
			}
		}

		public virtual void SetupRouter()
		{
			// templates library
			SPServices.RouterFactory.AddOrUpdateTemplate(
				Const.Router.Web.ServiceName,
				new RouterTemplate
					{
						Name = Const.Templates.LibTemplatesKey,
						Strict = false,
						Type = "SPList",
						Uri = "/Templates"
					}
				);
		}
	}
}